// Settings.cpp : implementation file
//

#include "stdafx.h"
#include "Settings.h"


#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CSettings dialog


CSettings::CSettings(CWnd* pParent /*=NULL*/)
	: CDialog(CSettings::IDD, pParent)
{
	//{{AFX_DATA_INIT(CSettings)
	m_isFillBG = FALSE;
	m_isMon = FALSE;
	m_isRem = FALSE;
	m_isTransBG = FALSE;
	m_isWeekDay = FALSE;
	m_isWeekNum = FALSE;
	m_isO = FALSE;
	m_isX = FALSE;
	m_linewidth = _T("");
	m_monplas = _T("");
	m_RemFile = _T("");
	m_MonNames = _T("");
	m_WeekDays = _T("");
	//}}AFX_DATA_INIT

	ZeroMemory(&m_lf,sizeof(m_lf));
}


void CSettings::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CSettings)
	DDX_Control(pDX, IDC_BUTTON_COLOR6, m_cb6);
	DDX_Control(pDX, IDC_BUTTON_COLOR5, m_cb5);
	DDX_Control(pDX, IDC_BUTTON_COLOR4, m_cb4);
	DDX_Control(pDX, IDC_BUTTON_COLOR3, m_cb3);
	DDX_Control(pDX, IDC_BUTTON_COLOR2, m_cb2);
	DDX_Control(pDX, IDC_BUTTON_COLOR1, m_cb1);
	DDX_Check(pDX, IDC_CHECK_ISFILLBG, m_isFillBG);
	DDX_Check(pDX, IDC_CHECK_ISMON, m_isMon);
	DDX_Check(pDX, IDC_CHECK_ISREM, m_isRem);
	DDX_Check(pDX, IDC_CHECK_ISTRANSBG, m_isTransBG);
	DDX_Check(pDX, IDC_CHECK_ISWEEKDAY, m_isWeekDay);
	DDX_Check(pDX, IDC_CHECK_ISWEEKNUM, m_isWeekNum);
	DDX_Check(pDX, IDC_CHECK_ISO, m_isO);
	DDX_Check(pDX, IDC_CHECK_ISX, m_isX);
	DDX_Text(pDX, IDC_EDIT_LINEWIDTH, m_linewidth);
	DDX_Text(pDX, IDC_EDIT_MONPLAS, m_monplas);
	DDX_Text(pDX, IDC_EDIT_REMFILE, m_RemFile);
	DDX_Text(pDX, IDC_EDIT_MONNAMES, m_MonNames);
	DDX_Text(pDX, IDC_EDIT_WEEKDAYS, m_WeekDays);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CSettings, CDialog)
	//{{AFX_MSG_MAP(CSettings)
	ON_BN_CLICKED(IDC_CHECK_ISTRANSBG, OnCheckIsTransBG)
	ON_BN_CLICKED(IDC_BUTTON_FONT, OnButtonFont)
	ON_BN_CLICKED(IDC_CHECK_ISX, OnCheckIsX)
	ON_BN_CLICKED(IDC_CHECK_ISO, OnCheckIsO)
	ON_BN_CLICKED(IDC_BUTTON_REMBROWSE, OnButtonRemBrowse)
	ON_BN_CLICKED(IDC_CHECK_ISREM, OnCheckIsRem)
	ON_NOTIFY(UDN_DELTAPOS, IDC_SPIN_LINE, OnDeltaposSpinLine)
	ON_NOTIFY(UDN_DELTAPOS, IDC_SPIN_MON, OnDeltaposSpinMon)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CSettings message handlers

void CSettings::OnCheckIsTransBG() 
{
	UpdateData(TRUE);	
	GetDlgItem(IDC_BUTTON_COLOR1)->EnableWindow(!m_isTransBG);
	GetDlgItem(IDC_CHECK_ISFILLBG)->EnableWindow(!m_isTransBG);
}

void CSettings::OnButtonFont() 
{
	CFontDialog dlg(&m_lf,CF_SCREENFONTS,NULL,this);
	if (dlg.DoModal() == IDOK)
	{	dlg.GetCurrentFont(&m_lf);
	}		

}

void CSettings::OnCheckIsX() 
{
	UpdateData(TRUE);
	GetDlgItem(IDC_EDIT_LINEWIDTH)->EnableWindow(m_isX|m_isO);
}

void CSettings::OnCheckIsO() 
{
	UpdateData(TRUE);
	GetDlgItem(IDC_EDIT_LINEWIDTH)->EnableWindow(m_isX|m_isO);
	
}

BOOL CSettings::OnInitDialog() 
{
	CDialog::OnInitDialog();
	
#ifndef _DEBUG 
	GetDlgItem(IDC_EDIT_REMFILE)->EnableWindow(FALSE);
	GetDlgItem(IDC_BUTTON_REMBROWSE)->EnableWindow(FALSE);
#endif

	OnCheckIsX();
	OnCheckIsTransBG();
	OnCheckIsRem() ;

	

	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

void CSettings::OnButtonRemBrowse() 
{
	CString S;
	S.LoadString(IDS_INIFILES);
	CFileDialog dlg (TRUE, NULL, NULL, 0,S, this);
	if (dlg.DoModal() == IDOK) S=dlg.GetPathName();
	if (S!="") GetDlgItem(IDC_EDIT_REMFILE)->SetWindowText(S);

}

void CSettings::OnCheckIsRem() 
{
	UpdateData(TRUE);
#ifdef _DEBUG
	GetDlgItem(IDC_EDIT_REMFILE)->EnableWindow(m_isRem);
	GetDlgItem(IDC_BUTTON_REMBROWSE)->EnableWindow(m_isRem);
#endif

}



void CSettings::OnDeltaposSpinLine(NMHDR* pNMHDR, LRESULT* pResult) 
{
	NM_UPDOWN* pNMUpDown = (NM_UPDOWN*)pNMHDR;
	
	UpdateData(TRUE);
	int N=atoi(m_linewidth)-pNMUpDown->iDelta;
	if (N<0) N=0;
	if (N>30) N=30;
	m_linewidth.Format("%i",N);
	UpdateData(FALSE);
	*pResult = 0;
}

void CSettings::OnDeltaposSpinMon(NMHDR* pNMHDR, LRESULT* pResult) 
{
	NM_UPDOWN* pNMUpDown = (NM_UPDOWN*)pNMHDR;
	
	UpdateData(TRUE);
	int N=atoi(m_monplas)-pNMUpDown->iDelta;
	if (N<-12) N=-12;
	if (N>12) N=12;
	m_monplas.Format("%i",N);
	UpdateData(FALSE);
	
	*pResult = 0;
}
